package java_thinking.unit_17._17_2_6;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Desc:   1
 * @author: cww
 * @DateTime: 2019-04-10 22:30
 */
class StringAddress {
    private String s;

    public StringAddress(String s) {
        this.s = s;
    }

    @Override
    public String toString() {
        return super.toString()+" "+s;
    }
}
public class FillingLists {
    public static void main(String[] args) {
        StringAddress stringAddress = new StringAddress("rr");
        System.out.println(stringAddress);
        //生成的都是对同一个对象的引用
        List<StringAddress> stringAddressList = new ArrayList<>(Collections.nCopies(4,new StringAddress("Hello")));
        System.out.println(stringAddressList);
        //fill只能替换已经在List中存在的元素
        Collections.fill(stringAddressList,new StringAddress("wold"));
        System.out.println(stringAddressList);

    }
}
